package edu.nctu.csie.jichang.dp.behavioral;

import java.util.Stack;

public class Memento {
	public static void main(String[] args) {
		Caretaker tCaretaker = new Caretaker();
		MClass tMClass = new MClass("1");
		System.out.println(tMClass);
		tCaretaker.stack.push(tMClass.setValue("2"));
		System.out.println(tMClass);
		tCaretaker.stack.push(tMClass.setValue("3"));
		System.out.println(tMClass);
		tMClass.reverseValue(tCaretaker.stack.pop());
		System.out.println(tMClass);
		tMClass.reverseValue(tCaretaker.stack.pop());
		System.out.println(tMClass);
	}
}
class MClass{
	String value;
	MClass(String value) {this.value = value;}
	MementoMClass setValue(String value){
		MementoMClass tOut = new MementoMClass(this.value);
		this.value = value;
		return tOut;
	}
	void reverseValue(MementoMClass memento){
		this.value = memento.value;
	}
	public String toString() { return value;}
}
class MementoMClass{
	String value;
	MementoMClass(String value) {this.value = value;}
}
class Caretaker{
	Stack<MementoMClass> stack = new Stack<MementoMClass>();
}